package org.thesis.adapter;

import java.util.List;

import org.thesis.doituong.econtact;

import org.thesis.R;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class econtact_adapter extends ArrayAdapter<econtact>
{
	Activity context;
	List<econtact>list;
	public econtact_adapter(Activity context,  List<econtact> list) {
		super(context, R.layout.row_email, list);
		this.context = context;
		this.list = list;
		// TODO Auto-generated constructor stub
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View v = null;
		if(convertView == null)
		{
			LayoutInflater li = context.getLayoutInflater();
			v = li.inflate(R.layout.row_email, null);
		}
		else
		{
			v = convertView;
		}
		
		final econtact e = list.get(position);
		TextView txt_name = (TextView) v.findViewById(R.id.txt_getmail_name);
		TextView txt_email = (TextView) v.findViewById(R.id.txt_getmail_email);
		CheckBox cb_check = (CheckBox) v.findViewById(R.id.cb_getmail_check);
		cb_check.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				CheckBox cb = (CheckBox) v.findViewById(R.id.cb_getmail_check);
				if(cb.isChecked())
				{
					e.setCheck(true);
				}
				else
				{
					e.setCheck(false);
				}
			}
		});
		txt_name.setText(e.getName());
		txt_email.setText(e.getEmail());
		cb_check.setChecked(e.isCheck());
		return v;
	}
	

}
